﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Traceability.App.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UpfileController : ControllerBase
    {
        [HttpPost]
        public IActionResult Upfile()
        {
            try
            {
                string str = "";
                var fd = Request.Form.Files;
                foreach(var item in fd)
                {
                    var filepath = Directory.GetCurrentDirectory() + "/File/" + item.FileName;
                    using (var fs=new FileStream(filepath,FileMode.Create))
                    {
                        item.CopyTo(fs);
                    }
                    str += "https://localhost:7235/File/" + item.FileName;
                }
                return Ok(str);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
